package view.viewComponents 
{
	import controller.EventBus;
	import controller.ZeldaModelEvent;
	import model.data.InventoryObjectTypes;
	import org.flixel.FlxSprite;
	
	/**
	 * ...
	 * @author Gaz Williams
	 * 
	 * the inventory displays the players currently held inventory item
	 * 
	 */
	
	public class Inventory extends FlxSprite 
	{
		
		// dead rat
		[Embed(source="../../../embedded/inventory_rat.png")]
		private var ratTexture:Class;
		
		// fridge handle
		[Embed(source="../../../embedded/inventory_fridgehandle.png")]
		private var fridgeTexture:Class;
		
		//gaffa
		[Embed(source='../../../embedded/inventory_gaffa.png')]
		private var gaffaTexture:Class;
		
		// managers trophy
		[Embed(source="../../../embedded/inventory_trophy.png")]
		private var trophyTexture:Class;
		
		//paper cup
		[Embed(source='../../../embedded/inventory_papercup.png')]
		private var cupTexture:Class;
		
		//paper cup with sand
		[Embed(source='../../../embedded/inventory_papercupwithsand.png')]
		private var cupWithSandTexture:Class;
		
		//wood splinter
		[Embed(source='../../../embedded/inventory_splinter.png')]
		private var splinterTexture:Class;
		
		// empty inventory holder
		[Embed(source = '../../../embedded/inventory_empty.png')]
		private var emptyTexture:Class;
		
		
		private var bus:EventBus;
		
		public function Inventory(X:Number=0, Y:Number=0, SimpleGraphic:Class=null) 
		{
			super(X, Y, SimpleGraphic);
			
			solid = false;
			
			bus = EventBus.getInstance();
			bus.addEventListener(ZeldaModelEvent.INVENTORY_UPDATED, handleInventoryUpdate);
			
			this.loadGraphic(emptyTexture, false, false, 32, 32, true);
		}
		
		override public function destroy():void 
		{
			bus.removeEventListener(ZeldaModelEvent.INVENTORY_UPDATED, handleInventoryUpdate);
			
			super.destroy();
		}
		
		private function handleInventoryUpdate(e:ZeldaModelEvent):void 
		{
			var received:InventoryObjectTypes = e.data as InventoryObjectTypes;
			
			trace("handleInventoryUpdated", received.type);
			
			//display the new inventory item
			switch (received.type) 
			{
				case InventoryObjectTypes.DEAD_RAT:
					this.loadGraphic(ratTexture, false, false, 32, 32, true);
				break;
				case InventoryObjectTypes.FRIDGE_HANDLE:
					this.loadGraphic(fridgeTexture, false, false, 32, 32, true);
				break;
				case InventoryObjectTypes.GAFFER_TAPE:
					this.loadGraphic(gaffaTexture, false, false, 32, 32, true);
				break;
				case InventoryObjectTypes.MANAGERS_TROPHY:
					this.loadGraphic(trophyTexture, false, false, 32, 32, true);
				break;
				default:
				case InventoryObjectTypes.NOTHING:
					this.loadGraphic(emptyTexture, false, false, 32, 32, true);
				break;
				case InventoryObjectTypes.PAPER_CUP:
					this.loadGraphic(cupTexture, false, false, 32, 32, true);
				break;
				case InventoryObjectTypes.PAPER_CUP_FILLED_WITH_SAND:
					this.loadGraphic(cupWithSandTexture, false, false, 32, 32, true);
				break;
				case InventoryObjectTypes.WOOD_SPLINTER:
					this.loadGraphic(splinterTexture, false, false, 32, 32, true);
				break;
			}
		}
		
	}

}